package com.sky.mapper;

import com.sky.entity.User;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;

import java.util.Map;

@Mapper
public interface UserMapper {
    /**
     * 根据用户名查询用户
     * @param id
     */
    @Select("select * from user where id=#{id}")
    User selectById(Long id);
    /**
     * 查询创建时间属于区间内的用户
     * @param
     */
    @Select("select count(*) from user where create_time between #{begin} and #{end}")
    Integer selectByCreateTime(Map map);

    /**
     * 根据openid查询用户
     * @param openid
     * @return
     */
    @Select("select * from user where openid=#{openid} ")
    User selectByOpenid(String openid);
    /**
     * 插入数据
     * @param user
     */
    @Options(useGeneratedKeys = true, keyProperty = "id")
    @Insert("INSERT into user (openid, name, create_time) values (#{openid},${name},#{createTime})")
    void insert(User user);

    @Select("select count(*) from user")
    Integer countByMap(Map map);

}
